package com.aaa.controller.sas;

import com.aaa.entity.LayData;
import com.aaa.entity.MyPage;
import com.aaa.entity.User;
import com.aaa.entity.sas.SasPlan;
import com.aaa.service.sas.SasPlanService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("sasplan")
public class SasPlanController {

    @Autowired
    private SasPlanService sasPlanService;

    /**
     * 添加计划
     * addplan
     */
    @PostMapping("addplan")
    @ResponseBody
    public LayData addplanname(SasPlan sasPlan,HttpSession session){
        User user =(User) session.getAttribute("user");
        Boolean isno = sasPlanService.addPlan(user,sasPlan);
        return new LayData(isno);
    }
    /**
     * 检测计划名称是否存在checkplanname
     */
    @PostMapping("checkplanname{planname}")
    @ResponseBody
    public LayData checkPlanName(@PathVariable String planname){
       Boolean isno = sasPlanService.checkPlanname(planname);
        return new LayData(isno);
    }

    /**
     * 检测验证码是否存在
     * @param sasPlan
     * @return
     */
    @PostMapping("checkCode")
    @ResponseBody
    public LayData checkcode(SasPlan sasPlan){
        Boolean isno = sasPlanService.checkcode(sasPlan);
        return new LayData(isno);
    }
    /**
     * 展示全部的计划
     * showplan
     */
    @RequestMapping("showplan")
    @ResponseBody
    public LayData showPlan(MyPage myPage,SasPlan sasPlan){
        PageInfo pageInfo = sasPlanService.showplan(myPage,sasPlan);
        LayData layData = new LayData(pageInfo);
        return layData;
    }
    /**
     * 修改计划的状态
     */
    @PostMapping("updPlanStatus")
    @ResponseBody
    public LayData updPlanStatus(SasPlan sasPlan){
        Boolean isno = sasPlanService.updPlanstatus(sasPlan);
        return new LayData(isno);
    }
    /**
     * 通过输入的验证码getByCode
     */
    @GetMapping("getByCode")
    @ResponseBody
    public LayData getPlanByCode(SasPlan sasPlan){
        SasPlan sasPlan1 = sasPlanService.findPlanByCode(sasPlan);
        return new LayData(sasPlan1);
    }
}
